<?php

class SessionHandler implements ISessionHandler {
	/**
	 * Object instance keeper
	 *
	 * @var SessionHandler
	 */
	private static $oInstance = null;

	/**
	 * Singleton
	 * 
	 * @return SessionHandler
	 */
	public static function getDefault(){
		if( self::$oInstance == null ){
			self::$oInstance = new SessionHandler();
		}
		return self::$oInstance;
	}
	
	private function __construct(){
		if(isset($_REQUEST["sessionId"]))
			session_id($_REQUEST["sessionId"]);
		
		session_start();
		
		/*
		ini_set("session.use_cookies","1");
		ini_set("session.use_only_cookies","1");
			$folder = explode('/',$_SERVER['REQUEST_URI']);
		if (count($folder)>=2){
			//we have subfolder			
			array_pop($folder);
			$folder = implode('/',$folder);
		}
		ini_set("session.cookie_path","{$folder}");
		//ini_set("session.cookie_domain","/aaaa/");
		
		 
		//session.trans_sid  - wyaczyc
		//session.cookie_lifetime - długość ciasteczka sesyjnego
		
		
		  //TODO: włączyć !!!???
		$lifetime = 60 * (int) ArrowSettings::getDefault()->getSetting( "global.app.session_life_time" ); 
		$dom = explode( "/", $_SERVER["REQUEST_URI"] ) ;
		array_pop($dom) ;
		$dom = implode( "/", $dom ) ;
		$host = $_SERVER["HTTP_HOST"].$dom ;
		if( $lifetime > 0 ) session_set_cookie_params( $lifetime ); 
			
		// przeciwdziałanie adopcji sesji
		$now = time() ;
		if( !isset( $_SESSION['_arrow_']['own_session'] ) ) {
			$this->regenerate();
			$_SESSION['_arrow_']['own_session'] = time() ;
		} else {
			if ( (int)$_SESSION['_arrow_']['own_session'] + $lifetime < $now ) {    // kontrola czasu trwania sessji
				$sessionName = session_name(); $_SESSION = array();
			    if (isset($_COOKIE[$sessionName])) {
			        setcookie($sessionName, '', $now-3600, '/');
			    }	
			    session_destroy();		
			} else $_SESSION['_arrow_']['own_session'] = time() ;
		}*/
	}
	
	public function regenerate() {
		session_regenerate_id( true );
	}


}

?>